/*
 * @Author: your name
 * @Date: 2021-12-23 16:27:43
 * @LastEditTime: 2021-12-27 07:57:57
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \day12 ts 路由 月考\my-app\src\mock\mock.tsx
 */
import Mock from "mockjs"
import mjson from "./mock.json"


Mock.mock("/api/login",(params:any)=>{
    console.log(params);
    let info=JSON.parse(params.body)
    let flag=mjson.some(item=>item.name===info.name&&item.pwd===info.pwd)
    if(flag){
        return {
            code:0,
            msg:"登录成功"
        }
    }else{
        return {
            code:1,
            msg:"登录失败"
        }
    }
})

Mock.mock("/api/list",(params:any)=>{
    let {page,pagesize}=JSON.parse(params.body)
    console.log(page,pagesize);
    
    let startIndex=(page-1)*pagesize+1
    console.log(startIndex);
    
    return Mock.mock({
            [`list|${pagesize}`]:[{
            "id":"@id",
            "img":"@image(100x100,@color)",
            "name":"@ctitle(4,8)",
            "title":"@ctitle",
            "city|1-5":1,
            "typenum|1-2":1,
            "typesort|1-2":1,
            "price|10-80":0
        }]
    })
})

